<template>
  <a-list :bordered="false" :scrollbar="true" :max-height="240">
    <a-list-item v-for="item in renderList" :key="item.tnId" action-layout="vertical" :style="{
        opacity: item.tnStats == 2 ? 0.5 : 1,
      }" @click="updateStat(item)">

      <!-- <template #extra>
  <a-tag :color="item.tnStats === 1 ? 'gray' : 'green'">{{ item.tnStats === 1 ? "未读" : "已读" }}</a-tag>
</template> -->

      <!-- <a-tag v-if="item.messageType === 0" color="gray">未开始</a-tag>
        <a-tag v-else-if="item.messageType === 1" color="green">已开通</a-tag>
        <a-tag v-else-if="item.messageType === 2" color="blue">进行中</a-tag>
        <a-tag v-else-if="item.messageType === 3" color="red">即将到期</a-tag> -->

      <div class="item-wrap" @click="onItemClick(item)">
        <span class="right1-class">
          <span class="right-flex-class" v-if="item.tnType!=3">
            <a-tag @click="updateStat(item)" :color="item.tnStats === 1 ? 'gray' : 'green'">{{ item.tnStats === 1 ? "未读" : "已读" }}</a-tag>
          </span>

          <span class="right-flex-class" v-else>
            <a-tag v-if="item.tnBehavior === 1" color="gray" @click="updatetnBehavior(item.tnId,3)">未开始</a-tag>
            <a-tag v-else-if="item.tnBehavior === 3" color="blue" @click="updatetnBehavior(item.tnId,2)">进行中</a-tag>
           <a-tag v-else-if="item.tnBehavior === 2" color="green">已完成</a-tag>
          </span>
        </span>
        <a-list-item-meta>
          <template v-if="item.imgUrl" #avatar>
            <a-avatar shape="circle">
              <img v-if="item.imgUrl" :src="item.imgUrl" />
              <icon-desktop v-else />
            </a-avatar>
          </template>
          <template #title>
            <a-space :size="4">
              <span>{{ item.tnTitle }}</span>
              <a-typography-text type="secondary">
                {{ item.tnContent }}
              </a-typography-text>
            </a-space>
          </template>
          <template #description>
            <div>
              <a-typography-paragraph :ellipsis="{
                rows: 1,
              }">{{ item.tnContent }}</a-typography-paragraph>
              <a-typography-text v-if="item.tnType === 1" class="time-text">
                {{ item.tnTime }}
              </a-typography-text>
            </div>
          </template>
        </a-list-item-meta>
      </div>
    </a-list-item>
    <template #footer>
      <a-space fill :size="0" :class="{ 'add-border-top': renderList.length < showMax }">
        <div class="footer-wrap">
          <a-link @click="allRead">{{ $t('messageBox.allRead') }}</a-link>
        </div>
        <!-- <div class="footer-wrap">
          <a-link>{{ $t('messageBox.viewMore') }}</a-link>
        </div> -->
      </a-space>
    </template>
    <div v-if="renderList.length && renderList.length < 3" :style="{ height: (showMax - renderList.length) * 86 + 'px' }">
    </div>
  </a-list>
</template>

<script lang="ts" setup>
import { PropType, ref, reactive, toRefs } from 'vue';
import { MessageRecord, MessageListType } from '@/api/message';
import api from '@/api/sys/Tnotice'

const tagKey = ref(0)

const arrs = { 1: "通知", 2: "消息", 3: "代办" }
const props = defineProps({
  unreadCount: {
    type: Number,
    default: 0,
  },
  messageType: {
    type: String,
  },
  renderList: {
    type: Array,
    default:[]
  }
});
/**
*  获取当前通知
*/
// const list = () => {
//   api.list(1).then(({ data }) => {
//     renderList.value = data.data.list
//     console.log(renderList);
//     toRefs(renderList)
//   })
// }


const updatetnBehavior=(id,tnBehavior)=>{
    var data={
       tnId:id,
       tnBehavior:tnBehavior
    }
    api.udpateStr(data).then(res => {
     // emit('itemClick', [...props.renderList]);
    }) 
}

const updateStat = (item) => {
  if(item.tnType!=3){
    item.tnStats = 2
    api.udpateStr(item).then(res => {
     // emit('itemClick', [...props.renderList]);
    })    
  }

}


const emit = defineEmits(['itemClick']);
const allRead = () => {
  //emit('itemClick', [...props.renderList]);
  var data = props.renderList.map(i => {
    return {
      tnId: i.tnId,
      tnStats: 2
    }
  })
  api.udpatebatchWord(data).then(res => {
    //emit('itemClick', [...props.renderList]);
  })
};

const onItemClick = (item: MessageRecord) => {
  if (!item.status) {
   // emit('itemClick', [item]);
  }
};
const showMax = 3;
</script>

<style scoped lang="less">
.right-flex-class {
  position: absolute;
  margin-top: 3vw;
}

.right1-class {
  position: relative;
  display: flex;
  justify-content: right;
  width: 100%;
  align-items: center;
}

:deep(.arco-list) {
  .arco-list-item {
    min-height: 86px;
    border-bottom: 1px solid rgb(var(--gray-3));
  }

  .arco-list-item-extra {
    position: absolute;
    right: 20px;
  }

  .arco-list-item-meta-content {
    flex: 1;
  }

  .item-wrap {
    cursor: pointer;
  }

  .time-text {
    font-size: 12px;
    color: rgb(var(--gray-6));
  }

  .arco-empty {
    display: none;
  }

  .arco-list-footer {
    padding: 0;
    height: 50px;
    line-height: 50px;
    border-top: none;

    .arco-space-item {
      width: 100%;
      border-right: 1px solid rgb(var(--gray-3));

      &:last-child {
        border-right: none;
      }
    }

    .add-border-top {
      border-top: 1px solid rgb(var(--gray-3));
    }
    .arco-space-item{
       display: grid;
    }
  }

  .footer-wrap {
    text-align: center;
  }

  .arco-typography {
    margin-bottom: 0;
  }

  .add-border {
    border-top: 1px solid rgb(var(--gray-3));
  }
}
</style>
